const request = require("request");

module.exports = {
  async getAddr(ip) {
    const options = {
      url: `https://searchplugin.csdn.net/api/v1/ip/get?ip=${ip}`, // 请求的URL
      method: "GET", // 请求方法
    };
    // 发送请求并返回数据
    await new Promise((resolve, reject) => {
      request(options, (error, response, body) => {
        if (error) {
          return resolve('')
          // return reject(error.message)
        }
        let result = JSON.parse(response.body);
        if (result.code === 200) {
          return resolve(result.msg)
        } else {
          return resolve('')
        }
      });
    });
  },
};

